package com.ljt.springsecuritylogin.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ljt.springsecuritylogin.domain.Users;
import com.ljt.springsecuritylogin.service.UsersService;
import com.ljt.springsecuritylogin.mapper.UsersMapper;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Optional;

/**
* @author 六件套
* @description 针对表【users】的数据库操作Service实现
* @createDate 2025-06-17 17:15:58
*/
@Service
public class UsersServiceImpl extends ServiceImpl<UsersMapper, Users>
    implements UsersService, UserDetailsService {

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        Users user = Optional.of(this.getOne(Wrappers.lambdaQuery(Users.class)
                .eq(Users::getUsername, username)))
                .orElseThrow(() -> new UsernameNotFoundException("用户不存在"));

        return new User(user.getUsername(), user.getPassword(), Collections.emptyList());
    }
}




